import React from 'react';
import { Modal, Input, message } from 'antd';

interface EditNameModalProps {
  visible: boolean;
  onCancel: () => void;
  onOk: (name: string) => void;
  initialName: string;
}

const EditNameModal: React.FC<EditNameModalProps> = ({ visible, onCancel, onOk, initialName }) => {
  const [newName, setNewName] = React.useState(initialName);

  React.useEffect(() => {
    setNewName(initialName);
  }, [initialName]);

  const handleOk = () => {
    if (!newName.trim()) {
      message.warning('名称不能为空');
      return;
    }
    onOk(newName);
  };

  return (
    <Modal
      title="修改名称"
      open={visible}
      onOk={handleOk}
      onCancel={() => {
        onCancel();
        setNewName(initialName);
      }}
      okText="确认"
      cancelText="取消"
    >
      <Input
        placeholder="请输入新名称"
        value={newName}
        onChange={(e) => setNewName(e.target.value)}
        maxLength={20}
      />
    </Modal>
  );
};

export default EditNameModal; 